<?php if (Yii::app()->session["member_level"] != "admin" and Yii::app()->session["member_id"] == NULL): 
echo $this->redirect(Yii::app()->homeUrl);
endif; ?>
<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'productcategory-form',
    'enableAjaxValidation' => false,
    'htmlOptions' => array(
        'enctype' => 'multipart/form-data',
    ),
        ));
?>

<div class="panel" style="margin-left: 10px">
    <div class="panel_header">ข้อมูลสินค้า</div>
    <div class="panel_header"><?php echo CHtml::link("กลับหน้าแรก", "index.php?r=Product/Product"); ?></div>
    <div class="panel_body grid-view">
        <table class="items" width="100%">
            <thead>
                <tr>
                    <th width="370px">กรอกข้อมูล</th>
                    <!--<th>กลุ่มผู้ใช้งานระบบ</th>-->
                </tr>
            </thead>
            <tbody>
                <tr valign="top">
                    <td>
                        <div>
                            <p>Fields with * are required.</p>
                        </div>
                        <div>   
                            <?php
                            $records = ProductCategory::model()->findAll();
                            $list = CHtml::listData($records, 'id', 'product_category_name_thai');
                            echo $form->labelEx($model, "product_category_id");
                            echo $form->dropDownList($model,'product_category_id', $list, array('empty' => '(Select a group'));
                            ?>             
                        </div>
                        <div>
                            <?php echo $form->labelEx($model, "product_code"); ?>
                            <?php echo $form->textField($model, "product_code"); ?>
                        </div>
                        <div>
                            <?php echo $form->labelEx($model, "product_name_thai"); ?>
                            <?php echo $form->textField($model, "product_name_thai"); ?>
                        </div>
                        <div>
                            <?php echo $form->labelEx($model, "product_name_eng"); ?>
                            <?php echo $form->textField($model, "product_name_eng"); ?>
                        </div>
                        <div>
                            <?php echo $form->labelEx($model, "product_description"); ?>
                            <?php echo $form->textArea($model, "product_description",array("cols"=>50,"rows"=>8)); ?>
                        </div>
                        <div>
                            <?php echo $form->labelEx($model, "product_cost"); ?>
                            <?php echo $form->textField($model, "product_cost"); ?>
                        </div>
                        <div>
                            <?php echo $form->labelEx($model,"product_picture_name"); ?>
<!--                            <?php // echo CHtml::activeFileField($model, "product_picture_name"); ?>  // by this we can upload image-->
                            <?php echo $form->fileField($model, "product_picture_name"); ?> 
                            <?php echo $form->error($model,"product_picture_name"); ?>
                        </div>
                        <?php if($model->isNewRecord!='1'){ ?>
                        <div>
                                <?php echo $form->labelEx($model,"product_picture_name"); ?>
                                 <?php // echo CHtml::image(Yii::app()->request->baseUrl.'/banner/'.$model->image,"image",array("width"=>200)); ?>  
                                 <?php echo CHtml::image("images/product/".$model->product_picture_name,"product_picture_name",array("width"=>200)); ?>
                                 <?php // echo CHtml::image(Yii::app()->request->baseUrl.'/banner/'.$model->image,"image",array("width"=>200)); ?>  
                        </div>
                                <?php } ?>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <?php echo $form->hiddenField($model,"id"); ?>
                        <?php echo CHtml::submitButton("บันทึกรายการ >", array("class" => "button")); ?>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<?php $this->endWidget(); ?>